package pers.bc.utils.yonyou;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import nc.bs.dao.DAOException;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.ic.m4y.entity.TransOutBodyVO;
import nc.vo.ic.m4y.entity.TransOutHeadVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nccloud.framework.web.ui.model.row.Cell;
import nccloud.framework.web.ui.model.row.Row;
import pers.bc.utils.pub.PubEnvUtil;
import pers.bc.utils.pub.StringUtil;

/**
 * 用友档案翻译查询，也支持前台查询
 ** 
 * @qualiFild pers.bc.utils.yonyou.YonyouTransUtil.java<br>
 * @author：LiBencheng<br>
 * @date Created on 2024-6-24<br>
 * @version 1.0<br>
 */
public final class YonRefTransUtil
{
    private YonRefTransUtil()
    {
    }
    
    private static ThreadLocal<YonRefTransUtil> transUtil = new ThreadLocal<YonRefTransUtil>();
    public static YonRefTransUtil yyTransUtil = new YonRefTransUtil();
    
    /**
     * *********************************************************** <br>
     * *说明：NCCLOUD 获取参照显示到前台 <br>
     * @see <br>
     * @param rows
     * @param cellName pk
     * @param refName
     * @param Zlass
     * @return
     * @throws Exception <br>
     * @Row[] <br>
     * @methods pers.bc.utils.yonyou.YonRefTransUtil#getRefValue <br>
     * @author LiBencheng <br>
     * @date Created on 2025年11月21日 <br>
     * @time 下午6:48:36 <br>
     * @version 1.0 <br>
     *************************************************************          <br>
     */
    public Row[] getRefValue(Row[] rows, String cellName, String refName, final Class<?> Zlass) throws Exception
    {
        for (int i = 0; i < PubEnvUtil.getSize(rows); i++)
        {
            Row row = rows[i];
            Cell cell = row.getCell(cellName);
            if (PubEnvUtil.isNotNullObj(cell))
            {
                SuperVO superVO = YonNccDB.bdUtil.getSuperVOById((String) cell.getValue(), Zlass);
                String display = StringUtil.valueOfEmpty(superVO.getAttributeValue(refName));
                cell.setDisplay(display);
            }
        }
        
        return rows;
    }
    
    public static YonRefTransUtil newUtil()
    {
        YonRefTransUtil df = transUtil.get();
        // if (null == df)
        // {
        // synchronized (YonyouTransUtil.class)
        // {
        if (null == df)
        {
            df = new YonRefTransUtil();
            transUtil.set(df);
        }
        // }
        // }
        
        return df;
    }
    
    /**
     * *********************************************************** <br>
     * *说明：组织_业务单元_销售组织版本信息 (org_salesorg_v) <br>
     * @see <br>
     * @param code
     * @return
     * @throws BusinessException <br>
     * @String <br>
     * @methods pers.bc.utils.yonyou.YonyouTransUtil#org_salesorg_v <br>
     * @author LiBencheng <br>
     * @date Created on 2024年8月4日 <br>
     * @time 17:03:15 <br>
     * @version 1.0 <br>
     *************************************************************          <br>
     */
    public String org_salesorg_v(String code) throws BusinessException
    {
        // String sql = "select pk_vid from org_salesorg_v where code = ? and pk_org = ? and (dr=0 or dr is
        // null)";
        String sql = "select pk_vid from org_salesorg_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        // para.addParam(pk_org);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]组织_业务单元_销售组织版本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据编码查询组织_部门信息 org_dept
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_dept(String code, String pk_org) throws BusinessException
    {
        String sql = "select pk_dept from org_dept where code = ? and pk_org = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        para.addParam(pk_org);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "," + pk_org + "]组织_部门信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据编码查询组织_部门信息 org_dept_v
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_dept_v(String code, String pk_org) throws BusinessException
    {
        String sql = "select pk_vid from org_dept where code = ? and pk_org = ? and (dr=0 or dr is null)  and enablestate = 2";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        para.addParam(pk_org);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "," + pk_org + "]组织_部门信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据编码查询组织_部门版本信息 org_dept_v
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_vid_dept(String code, String pk_org) throws BusinessException
    {
        String sql = "select pk_vid from org_dept_v where code = ? and pk_org = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        para.addParam(pk_org);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]组织_部门版本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 收付款类型
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String recpaytype(String code) throws BusinessException
    {
        String sql = "select pk_recpaytype  from fi_recpaytype where code = ? and nvl(dr,0) = 0";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]收付款类型未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据编码查询人员基本信息 bd_psndoc
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_bdpsndoc(String code) throws BusinessException
    {
        String sql = "select pk_psndoc from bd_psndoc where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]人员基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据 身份证号 查询人员基本信息 bd_psndoc
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_bdpsndocById(String id) throws BusinessException
    {
        String sql = "select pk_psndoc from bd_psndoc where id = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(id);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("身份证号[" + id + "]的人员基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据项目编码查询项目主键
     * 
     * @param project_code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_bdproject(String project_code) throws BusinessException
    {
        String sql = "select pk_project from bd_project where project_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(project_code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + project_code + "]项目档案未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询库存组织主键 org_stockorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_stockorg(String code) throws BusinessException
    {
        String sql = "select pk_stockorg from org_stockorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]库存组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织 主键 查询库存组织主键 org_stockorg_vid
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_stockorg_vid(String code) throws BusinessException
    {
        String sql = "select pk_vid from org_stockorg where pk_stockorg = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]库存组织(vid)未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询库存组织版本主键 org_stockorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_vid(String code) throws BusinessException
    {
        String sql = "select pk_vid from org_stockorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]库存组织版本未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询结算财务组织主键 org_financeorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_financeorg(String code) throws BusinessException
    {
        String sql = "select pk_financeorg from org_financeorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]结算财务组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询结算财务组织版本主键 org_financeorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_vid_financeorg(String code) throws BusinessException
    {
        String sql = "select pk_vid from org_financeorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]结算财务组织版本主键未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询采购组织主键 org_purchaseorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_purchaseorg(String code) throws BusinessException
    {
        String sql = "select pk_purchaseorg from org_purchaseorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]采购组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据组织编码查询采购组织版本主键 org_purchaseorg
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_vid_purchaseorg(String code) throws BusinessException
    {
        String sql = "select pk_vid from org_purchaseorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]采购组织版本主键未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据用户编码查询用户主键 sm_user
     * 
     * @param user_code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_cuserid(String user_code) throws BusinessException
    {
        String sql = "select cuserid from sm_user where user_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(user_code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + user_code + "]用户未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据单据类型编码和集团获取单据类型 bd_billtype
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_billtypeid(String billtypeCode, String pk_group) throws BusinessException
    {
        String sql = "select pk_billtypeid from bd_billtype where pk_billtypecode = ? and pk_group = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(billtypeCode);
        para.addParam(pk_group);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + billtypeCode + "]单据类型未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据集团编码查询集团主键
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String getPkGroupByCode(String code) throws BusinessException
    {
        String sql = "select PK_GROUP from org_group where code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]pk_group集团主键未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据单据类型编码获取单据类型 bd_billtype
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_billtypeid_code(String billtypeCode, String pk_group) throws BusinessException
    {
        String sql = "select pk_billtypeid from bd_billtype where pk_billtypecode = ? and pk_group = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(billtypeCode);
        para.addParam(pk_group);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + billtypeCode + "]单据类型未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据库存组织和仓库编码获取仓库 bd_stordoc
     * 
     * @param pk_ogr
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_stordoc(String pk_group, String code) throws BusinessException
    {
        String sql = "select pk_stordoc from bd_stordoc where PK_GROUP = ? and code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(pk_group);
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + pk_group + "---" + code + "]仓库未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据库存组织和仓库编码获取仓库 bd_stordoc
     * 
     * @param pk_ogr
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_stordoc_org(String pk_org, String code) throws BusinessException
    {
        String sql = "select pk_stordoc from bd_stordoc where pk_org = ? and code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(pk_org);
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + pk_org + code + "]仓库未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据物流组织编码获取组织_业务单元_物流组织版本信息 org_trafficorg_v
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_vid_trafficorg(String code) throws BusinessException
    {
        String sql = "select pk_vid from org_trafficorg_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物流组织版本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物流组织编码获取组织_业务单元_物流组织 org_trafficorg
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_trafficorg(String code) throws BusinessException
    {
        String sql = "select pk_trafficorg from org_trafficorg where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物流组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取计量单位 bd_measdoc<br>
     * bd_material_v. pk_measdoc 主计量单位
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_measdoc_mater(String material_Code) throws BusinessException
    {
        String sql = "select pk_measdoc from bd_material_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(material_Code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[物料编码:" + material_Code + "]计量单位未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据计量单位编码获取计量单位 bd_measdoc
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_measdoc(String code) throws BusinessException
    {
        String sql = "select pk_measdoc from bd_measdoc where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]计量单位未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取物料基本信息 bd_material_v
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_source(String code) throws BusinessException
    {
        String sql = "select pk_source from bd_material_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物料基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取物料pk
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String bd_material(String code) throws BusinessException
    {
        String sql = "select pk_material from bd_material where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物料基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取物料基本信息主单位 bd_material_v
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_measdoc_material(String code) throws BusinessException
    {
        String sql = "select pk_measdoc from bd_material_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物料基本信息对应主单位未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取物料基本信息多版本主键 bd_material_v
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String translatorpk_material_v(String code) throws BusinessException
    {
        String sql = "select pk_material from bd_material_v where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]物料基本信息对应多版本主键未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料主键获取辅计量单位
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String bd_materialconvert(String pk) throws BusinessException
    {
        String sql = "select PK_MEASDOC from bd_materialconvert where PK_MATERIAL = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(pk);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + pk + "]根据物料查询计量单位失败");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据物料编码获取换算率
     * 
     * @param billtypeCode
     * @return
     * @throws BusinessException
     */
    public String vchangerate(String pk_material) throws BusinessException
    {
        String sql = "select MEASRATE from bd_materialconvert where pk_material = ?;";
        SQLParameter para = new SQLParameter();
        para.addParam(pk_material);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + pk_material + "]换算率未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据国家地区编码获取国家地区 bd_countryzone
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_country(String code) throws BusinessException
    {
        String sql = "select pk_country from bd_countryzone where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]国家地区未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据核心单据编码找业务流程 bd_busitype
     * 
     * @param primarybilltype
     * @return
     * @throws Exception
     */
    public String translatorpk_busitype(String primarybilltype) throws BusinessException
    {
        String sql =
            "SELECT pk_busitype FROM bd_busitype WHERE validity=1 and pk_group!='global00000000000000' and primarybilltype = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(primarybilltype);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + primarybilltype + "]业务流程未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据业务流程编码找业务流程 bd_busitype
     * 
     * @param busicode
     * @return
     * @throws Exception
     */
    public String translatorpk_busitype_code(String busicode) throws BusinessException
    {
        String sql =
            "SELECT pk_busitype FROM bd_busitype WHERE validity='1' and pk_group !='global00000000000000' and busicode = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(busicode);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + busicode + "]业务流程未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据增值税税码编码获取增值税税码税率 bd_taxcode
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_taxcode(String code) throws BusinessException
    {
        String sql = "select pk_taxcode from bd_taxcode where code = ? and enablestate = 2 and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]增值税税码税率未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据币种编码获取币种 bd_currtype
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_currtype(String code) throws BusinessException
    {
        String sql = "select pk_currtype from bd_currtype where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]币种未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据组织编码获取账簿_财务核算账簿 org_accountingbook
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_accountingbook(String code) throws BusinessException
    {
        String sql = "select pk_accountingbook from org_accountingbook where code = '" + code + "-0001' and (dr=0 or dr is null)";
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]账簿不能为空或没有找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据使用状况编码获取使用状况 fa_usingstatus
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_usingstatus(String code) throws BusinessException
    {
        String sql = "select pk_usingstatus from fa_usingstatus where status_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]使用状况不能为空或没有找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据折旧方法编码获取折旧方法 fa_depmethod
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_depmethod(String code) throws BusinessException
    {
        String sql = "select pk_depmethod from fa_depmethod where depmethod_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            // if (StringUtils.isEmpty(rs)) {
            // throw new BusinessException("[" + code + "]折旧方法未找到");
            // }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据类别编码获取资产类别 fa_category
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_category(String code) throws BusinessException
    {
        String sql = "select pk_category from fa_category where cate_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]资产类别未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据增减方式编码获取增减方式 pam_addreducestyle
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_addreducestyle(String code) throws BusinessException
    {
        String sql = "select pk_addreducestyle from pam_addreducestyle where style_code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]增减方式未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据供应商编码获取供应商基本信息 bd_supplier
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_supplier(String code) throws BusinessException
    {
        String sql = "select pk_supplier from bd_supplier where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]供应商基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据组织编码查询组织 org_orgs
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_org(String code) throws BusinessException
    {
        String sql = "select pk_org from org_orgs where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 组织_业务单元_采购组织 (org_purchaseorg)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String org_purchaseorg(String code) throws BusinessException
    {
        String sql = "select pk_org from org_purchaseorg  where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]组织_业务单元_采购组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据客户编码查询客户基本信息 bd_customer
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_customer(String code) throws BusinessException
    {
        String sql = "select pk_customer from bd_customer where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]客户基本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据结算方式编码查询结算方式 bd_balatype
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_balatype(String code) throws BusinessException
    {
        String sql = "select pk_balatype from bd_balatype where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]结算方式未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 票据类型
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String notetype(String code) throws BusinessException
    {
        String sql = "select pk_notetype from bd_notetype where code = ? and nvl(dr,0) = 0";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]票据类型未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 票据签发回单
     * 
     * @param Code
     * @return
     * @throws BusinessException
     */
    public String translatorRegister(String code) throws BusinessException
    {
        String sql = "select pk_register  from  fbm_register  where fbmbillno = ? and nvl(dr,0) = 0 ";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]单位编码未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据银行账户编码查询银行账户子户 bd_bankaccsub
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_bankaccsub(String code) throws BusinessException
    {
        String sql = "select pk_bankaccsub from bd_bankaccsub where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]银行账户未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据银行账户编码查询银行账户子户 bd_bankaccsub
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_bankaccsubTop(String accnum) throws BusinessException
    {
        String sql = "select  top 1 pk_bankaccsub from bd_bankaccsub where accnum = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(accnum);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + accnum + "]银行账户未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 根据现金账户编码查询现金账户 bd_cashaccount
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String translatorpk_cashaccount(String code) throws BusinessException
    {
        String sql = "select pk_cashaccount from bd_cashaccount where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]现金账户未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
    }
    
    /**
     * 收支项目
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String inoutbusiclass(String code) throws BusinessException
    {
        String sql = "select pk_inoutbusiclass  from bd_inoutbusiclass  where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]收支项目未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据收支项目查询 成本费用
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String selectCbfyBySzxm(String code) throws BusinessException
    {
        String sql = "select def1 from bd_inoutbusiclass  where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("收支项目编码为[" + code + "]的成本费用未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 成本费用(自定义档案)生产厂商
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String defdoc(String code) throws BusinessException
    {
        String sql = "select pk_defdoc  from bd_defdoc  where code = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]成本费用or生产厂商未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 项目(isproject 自定义档案)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String isproject(String name) throws BusinessException
    {
        String sql = "select pk_defdoc  from bd_defdoc  where name = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(name);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + name + "]项目未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 资金来源
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String pam_capital_source(String source_name) throws BusinessException
    {
        String sql = "SELECT pk_defdoc from bd_defdoc WHERE pk_defdoclist = '1001AA10000000000BRY' AND name = ? and (dr=0 or dr is null)";
        SQLParameter para = new SQLParameter();
        para.addParam(source_name);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + source_name + "]资金来源 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 付款协议
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String bd_payment(String code) throws BusinessException
    {
        String sql = "SELECT pk_payment from bd_payment WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]付款协议未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 组织_业务单元_库存组织版本信息
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String org_stockorg_v(String code) throws BusinessException
    {
        String sql = "SELECT pk_vid from org_stockorg_v WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]库存组织未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 地点档案
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String bd_addressdoc(String code) throws BusinessException
    {
        String sql = "SELECT pk_addressdoc from bd_addressdoc WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]地点档案未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 地址簿 (bd_address)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String bd_address(String code) throws BusinessException
    {
        String sql = "SELECT pk_address from bd_address WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]地点档案未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 地区分类 (bd_areacl)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String bd_areacl(String code) throws BusinessException
    {
        String sql = "SELECT pk_areacl from bd_areacl WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]地区未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 组织_业务单元_财务组织版本信息 (org_financeorg_v)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String org_financeorg_v(String code) throws BusinessException
    {
        String sql = "SELECT pk_vid from org_financeorg_v WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]组织_业务单元_财务组织版本信息未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 优质优价方案主表 (purp_qpscheme)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String purp_qpscheme(String code) throws BusinessException
    {
        String sql = "SELECT pk_qpscheme from purp_qpscheme WHERE vschemecode = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]优质优价方案 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 采购合同 (ct_pu)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String ct_pu(String code) throws BusinessException
    {
        String sql = "SELECT pk_ct_pu from ct_pu WHERE vbillcode = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]采购合同 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 根据货位编号查询货位主键
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String bd_rack(String code) throws BusinessException
    {
        String sql = "SELECT pk_rack from bd_rack  WHERE code = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]货位主键  未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 结算路径主表 (to_settlepath)
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String to_settlepath(String code) throws BusinessException
    {
        String sql = "SELECT csettlepathid from to_settlepath  WHERE vpathcode = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]结算路径 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 根据交易类型查结算规则主表（to_settlerule ）
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String to_settlerule(String code) throws BusinessException
    {
        String sql = "select csettleruleid from to_settlerule where CTRANSTYPE = ? and FSETTLEMAINBODY = '2'";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]结算规则主表 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 
     * 根据结算规则主表查询子表（to_settlerule_b ）
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String to_settlerule_b(String csettleruleid) throws BusinessException
    {
        String sql = "select csettlerule_bid from TO_SETTLERULE_B where csettleruleid = ?";
        SQLParameter para = new SQLParameter();
        para.addParam(csettleruleid);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + csettleruleid + "]结算规则子表 未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    /**
     * 根据批次号编码和物料主键查询批次主键
     * 
     * @param code
     * @param pk_material
     * @return
     */
    public String getScmBatchcodeByCode(String code, String pk_material) throws BusinessException
    {
        if (StringUtils.isEmpty(code) || StringUtils.isEmpty(pk_material))
        {
            return null;
        }
        SQLParameter parameter = new SQLParameter();
        parameter.addParam(code);
        parameter.addParam(pk_material);
        String qrySql = "select pk_batchcode from scm_batchcode where dr=0 and vbatchcode  = ? and cmaterialoid = ? ;";
        try
        {
            String pk = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(qrySql, parameter, new ColumnProcessor());
            return pk;
        }
        catch (DAOException e)
        {
            
            throw new BusinessException("根据批次号编码和物料主键查询批次主键异常!" + e.getMessage());
        }
    }
    
    /**
     * 根据 调拨出库 源头 单据号查询调拨出库主键
     * 
     * @param code
     * @param pk_material
     * @return
     */
    public String getTransOutBySourceCode(String vsourcebillcode) throws BusinessException
    {
        if (StringUtils.isEmpty(vsourcebillcode))
        {
            return null;
        }
        SQLParameter parameter = new SQLParameter();
        parameter.addParam(vsourcebillcode);
        String qrySql = "select CGENERALHID from IC_TRANSOUT_B where vfirstbillcode  = ? and dr=0;";
        try
        {
            String pk = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(qrySql, parameter, new ColumnProcessor());
            return pk;
        }
        catch (DAOException e)
        {
            throw new BusinessException("根据源头单据号查询调拨出库表头 主键!" + e.getMessage());
        }
    }
    
    /**
     * 根据调拨出库主键查询调拨出库 表头VO
     * 
     * @param code
     * @param pk_material
     * @return
     */
    public TransOutHeadVO getTransOutHeadVOByPk(String pk) throws BusinessException
    {
        if (StringUtils.isEmpty(pk))
        {
            return null;
        }
        SQLParameter parameter = new SQLParameter();
        parameter.addParam(pk);
        String qrySql = "select * from IC_TRANSOUT_H where CGENERALHID = ?  and dr = 0 ;";
        try
        {
            TransOutHeadVO res = (TransOutHeadVO) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(qrySql, parameter,
                new BeanProcessor(TransOutHeadVO.class));
            if (res == null)
            {
                throw new BusinessException("[" + pk + "]调拨出库[表头]未找到");
            }
            return res;
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
    }
    
    /**
     * 根据调拨出库主键查询调拨出库 表体VO
     * 
     * @param code
     * @param pk_material
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<TransOutBodyVO> getTransOutBodyVOByPk(String pk) throws BusinessException
    {
        if (StringUtils.isEmpty(pk)) return null;
        SQLParameter parameter = new SQLParameter();
        parameter.addParam(pk);
        String qrySql = "select * from IC_TRANSOUT_B where CGENERALHID = ? and dr = 0;";
        try
        {
            List<TransOutBodyVO> res = (List<TransOutBodyVO>) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(qrySql, parameter,
                new BeanListProcessor(TransOutBodyVO.class));
            if (res == null || res.isEmpty())
            {
                throw new BusinessException("[" + pk + "]调拨出库[表体]未找到");
            }
            return res;
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
    }
    
    /**
     * 摘要
     * 
     * @param code
     * @return
     * @throws BusinessException
     */
    public String summary(String code) throws BusinessException
    {
        String sql = "select pk_summary  from fipub_summary where code = ? and nvl(dr,0) = 0";
        SQLParameter para = new SQLParameter();
        para.addParam(code);
        String rs = null;
        try
        {
            rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, para, new ColumnProcessor());
            if (StringUtils.isEmpty(rs))
            {
                throw new BusinessException("[" + code + "]摘要未找到");
            }
        }
        catch (DAOException e)
        {
            throw new BusinessException(e.getMessage());
        }
        
        return rs;
        
    }
    
    // 获取客商
    public String translatorpk_cust_sup(String string) throws BusinessException
    {
        String queryuserSql = "select pk_cust_sup from bd_cust_supplier where code ='" + string + "' and (dr=0 or dr is null) ";
        String rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(queryuserSql, new ColumnProcessor());
        
        if (StringUtils.isEmpty(rs))
        {
            throw new BusinessException("[" + string + "]减少对方单位未找到");
        }
        return rs;
    }
    
    // 获取减少原因
    public String translatorpk_reason(String code) throws BusinessException
    {
        String queryuserSql = "select pk_reason from fa_reason where reason_code ='" + code + "' and (dr=0 or dr is null) ";
        String rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(queryuserSql, new ColumnProcessor());
        
        if (StringUtils.isEmpty(rs))
        {
            throw new BusinessException("[" + code + "]减少原因未找到");
        }
        return rs;
    }
    
    /**
     * 20220214更新
     * 
     */
    // 获取组织信息
    public OrgVO getOrgVo(String code) throws BusinessException
    {
        String sql = "select * from org_orgs where code='" + code + "' and (dr=0 or dr is null) order by ts desc";
        OrgVO org = (OrgVO) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(sql, new BeanProcessor(OrgVO.class));
        if (org == null)
        {
            throw new BusinessException("[" + code + "]组织信息未找到");
        }
        return org;
    }
    
    // 获取组织信息
    public String getPk_org(String code) throws BusinessException
    {
        return getOrgVo(code).getPk_org();
    }
    
    // 获取使用人员主键
    public String translatorpsndoc(String code) throws BusinessException
    {
        String queryuserSql = "select pk_psndoc from bd_psndoc where code ='" + code + "' and (dr=0 or dr is null) ";
        String rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(queryuserSql, new ColumnProcessor());
        
        return rs;
    }
    
    // 根据其它出库外系统编码获取主键
    public void translatorOutBillByCode(String code, String source) throws BusinessException
    {
        String queryuserSql = "select cgeneralhid from ic_generalout_h where vdef44 = '" + code + "' " + "and vdef50 = '" + source
            + "' and (dr=0 or dr is null) ";
        String rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(queryuserSql, new ColumnProcessor());
        
        if (StringUtils.isNotEmpty(rs))
        {
            throw new BusinessException("[" + code + "]单据已存在");
        }
    }
    
    // 根据其它入库外系统编码获取主键
    public void translatorInBillByCode(String code, String source) throws BusinessException
    {
        String queryuserSql = "select cgeneralhid from ic_generalin_h where vdef44 = '" + code + "' " + "and vdef50 = '" + source
            + "' and (dr=0 or dr is null) ";
        String rs = (String) YonYouUtilbc.getBaseDAOQueryBSyC().executeQuery(queryuserSql, new ColumnProcessor());
        
        if (StringUtils.isNotEmpty(rs))
        {
            throw new BusinessException("[" + code + "]单据已存在");
        }
    }
}
